package ca.nfb.media.nfbPlayer.ui
{
	import ca.nfb.media.nfbPlayer.views.NFBPlayerView;
	import ca.nfb.media.nfbPlayer.views.Sharing;
	import ca.turbulent.media.Pyro;
	import ca.turbulent.media.events.PyroEvent
	
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.MovieClip;
	import flash.events.Event;
	import ca.turbulent.media.events.StatusUpdateEvent;
	
	public class TabIndexManager extends NFBPlayerView
	{
		public var _tabItems				:Array = new Array();
		
		public function TabIndexManager():void
		{
			super();
		}
		
		private function clearTabItems():void
		{
			var item:InteractiveObject;
			for (var i:Number=0; i<_tabItems.length; ++i)
			{
				item = _tabItems[i] as InteractiveObject;
				item.tabIndex = -1;
				item.tabEnabled = false;
			}
		}
		
		public function set tabItems(arr:Array):void
		{
			clearTabItems();
			var item:InteractiveObject;
			for (var i:Number=0; i<arr.length; ++i)
			{
				item = arr[i] as InteractiveObject;
				item.tabIndex = _tabItems.length+1;
				item.tabEnabled = true;
				_tabItems.push(item);
			}
		}
		
		public function appendTabItems(arr:Array):void
		{
			var item:InteractiveObject;
			
			for (var i:Number=0; i<arr.length; ++i)
			{
				item = arr[i] as InteractiveObject;
				item.tabIndex = _tabItems.length+1;
				item.tabEnabled = true;
				_tabItems.push(item);
			}
		}
		
		public function clearFromFocus(arr:Array):void
		{
			var item:InteractiveObject;
			for (var i:Number=0; i<arr.length; ++i)
			{
				item = arr[i] as InteractiveObject;
				item.tabIndex = -1;
				item.tabEnabled = false;
			}
		}
		
		
		
		override protected function streamStatusUpdated(evt:StatusUpdateEvent):void
		{
			switch(player.status)
			{
				case Pyro.STATUS_PLAYING:
				break;
				
				case Pyro.STATUS_PAUSED:
				break;
				
				case Pyro.STATUS_PENDING:
				break;
			}
		}
		
		override protected function coreStateUpdated(evt:Event=null):void
		{
			var myTabItems:Array = new Array();
			switch (core.currentState)
			{
				case NFBPlayer.DEFAULT_STATE:
				default:
				myTabItems.push(core.player);
				myTabItems.push(core.controlBar.playPauseButton_mc);
				
				if (core.enableSpeedOptionsButton)
					myTabItems.push(core.controlBar.optionsButton_mc);
				
				if (core.enableSharingButton)
					myTabItems.push(core.controlBar.sharingButton_mc);	
				
				if (core.enableCloseCaptionsButton)
					myTabItems.push(core.controlBar.closeCaptionsButton_mc);
					
				if (core.enableDescriptiveAudioButton)
					myTabItems.push(core.controlBar.descAudioButton_mc);	
				
				if (core.enableCartButton)
					myTabItems.push(core.controlBar.cartButton_mc);
							
				if (core.enableMoreInfosButton)
					myTabItems.push(core.controlBar.infosButton_mc);
					
				if (core.player.useFullScreen)
					myTabItems.push(core.controlBar.fullscreenButton_mc);	
				
				myTabItems.push(core.controlBar.smallLogoButton_mc);
				myTabItems.push(core.controlBar.menuButton_mc);
					
				this.tabItems = myTabItems; 
				break;
				
				case NFBPlayer.END_PLAYLIST_STATE:
				core.controlBar.bookmarksView.hideAllBookmarks();
				break;
				
				case NFBPlayer.FILE_NOT_FOUND_STATE:
				core.controlBar.bookmarksView.hideAllBookmarks();
				break;
				
				case NFBPlayer.MESSAGE_STATE:
				core.controlBar.bookmarksView.hideAllBookmarks();
				break;
				
				case NFBPlayer.MORE_INFOS_STATE:
				core.controlBar.bookmarksView.hideAllBookmarks();
				this.tabItems = [core.moreInfoView.closeButton_mc, core.moreInfoView.linkButton_mc];
				break;
				
				case NFBPlayer.OPTIONS_STATE:
				core.controlBar.bookmarksView.hideAllBookmarks();
				this.tabItems = [core.optionsView.closeButton_mc, core.optionsView.lowSpeed_mc, core.optionsView.standardSpeed_mc, core.optionsView.highSpeed_mc, core.optionsView.labels_mc];
				break;
				
				case NFBPlayer.PREVIEW_IMAGE_STATE:
				core.controlBar.bookmarksView.hideAllBookmarks();
				
				myTabItems.push(core.previewImage.bkgd_mc);
				myTabItems.push(core.controlBar.playPauseButton_mc);
				
				if (core.enableSpeedOptionsButton)
					myTabItems.push(core.controlBar.optionsButton_mc);
				
				if (core.enableSharingButton)
					myTabItems.push(core.controlBar.sharingButton_mc);	
				
				if (core.enableCloseCaptionsButton)
					myTabItems.push(core.controlBar.closeCaptionsButton_mc);
					
				if (core.enableDescriptiveAudioButton)
					myTabItems.push(core.controlBar.descAudioButton_mc);	
				
				if (core.enableCartButton)
					myTabItems.push(core.controlBar.cartButton_mc);
							
				if (core.enableMoreInfosButton)
					myTabItems.push(core.controlBar.infosButton_mc);
				
				myTabItems.push(core.controlBar.smallLogoButton_mc);
				myTabItems.push(core.controlBar.menuButton_mc);
					
				this.tabItems = myTabItems; 
				break;
				
				case NFBPlayer.SHARING_STATE:
				core.controlBar.bookmarksView.hideAllBookmarks();
				this.tabItems = [core.sharingView.closeButton_mc, core.sharingView.sharingButton_mc, core.sharingView.facebookButton_mc, core.sharingView.redditButton_mc, core.sharingView.stumbleUponButton_mc, core.sharingView.diggButton_mc, core.sharingView.deliciousButton_mc, core.sharingView.googleButton_mc, core.sharingView.selectLinkButton_mc, core.sharingView.selectEmbedButton_mc, core.sharingView.selectLinkButton_mc, core.sharingView.selectEmbedButton_mc];
				break;
				
			}
		}
	}	
}